package service

import (
	"ksd-social-api/modules/special/model"
	"ksd-social-api/modules/special/model/context"
)

/**
 * 用户点赞
 * @author feige
 * @date 2023-11-23
 * @version 1.0
 * @desc
 */
type SpecialUserLikeService struct {
}

/**
 * 点赞
 * @author feige
 * @date 2023-10-10
 * @version 1.0
 */
func (service *SpecialUserLikeService) SaveSpecialUserLike(ctx context.FavLikeContext) int64 {
	isFocus := specialUserLikeMapper.CountSpecialUserLike(ctx.UserId, ctx.Opid.Uint64(), ctx.SystemId)
	// 点赞
	if isFocus == -1 {
		var bbsUserLike model.SpecialUserLike
		bbsUserLike.UserId = ctx.UserId
		bbsUserLike.Avatar = ctx.Avatar
		bbsUserLike.Nickname = ctx.Nickname
		bbsUserLike.Username = ctx.Username
		bbsUserLike.Uuid = ctx.Uuid
		bbsUserLike.SystemId = ctx.SystemId
		bbsUserLike.SystemName = ctx.SystemName
		bbsUserLike.Opid = ctx.Opid.Uint64()
		bbsUserLike.IsFocus = 1
		specialUserLikeMapper.SaveSpecialUserLike(ctx.Opid.Uint64(), bbsUserLike)
		return 1
	}

	// 再点赞
	if isFocus == 0 {
		specialUserLikeMapper.RecoverSpecialUserLike(ctx.UserId, ctx.Opid.Uint64(), ctx.SystemId)
		return 1
	}

	// 取消点赞
	if isFocus == 1 {
		specialUserLikeMapper.CancelSpecialUserLike(ctx.UserId, ctx.Opid.Uint64(), ctx.SystemId)
		return 0
	}

	return 0
}

/**
 * 查询是否点赞
 * @author feige
 * @date 2023-11-23
 * @version 1.0
 * @desc
 */
func (service *SpecialUserLikeService) GetUserLike(userId uint64, focusId uint64, systemId uint64) int64 {
	return specialUserLikeMapper.CountSpecialUserLike(userId, focusId, systemId)
}

/*
- 删除点赞
- @author feige
- @date 2023-10-10
- @version 1.0
*/
func (service *SpecialUserLikeService) DelUserLike(ctx context.FavLikeDelContext) bool {
	return specialUserLikeMapper.DelSpecialUserLike(ctx.Id.Uint64(), ctx.UserId, ctx.SpecialId.Uint64(), ctx.SystemId)
}
